from django.contrib import admin
from .models import ChatSession, ChatMessage, RecommendedAction


@admin.register(ChatSession)
class ChatSessionAdmin(admin.ModelAdmin):
    list_display = ['title', 'user_profile', 'created_at', 'updated_at']
    list_filter = ['created_at', 'updated_at']
    search_fields = ['title', 'user_profile__user__username']
    ordering = ['-updated_at']


@admin.register(ChatMessage)
class ChatMessageAdmin(admin.ModelAdmin):
    list_display = ['session', 'role', 'content_preview', 'created_at']
    list_filter = ['role', 'created_at']
    search_fields = ['content', 'session__title']
    ordering = ['session', 'created_at']

    def content_preview(self, obj):
        return obj.content[:50] + '...' if len(obj.content) > 50 else obj.content
    content_preview.short_description = '消息预览'


@admin.register(RecommendedAction)
class RecommendedActionAdmin(admin.ModelAdmin):
    list_display = ['title', 'user_profile', 'priority', 'status', 'created_at']
    list_filter = ['status', 'priority', 'created_at']
    search_fields = ['title', 'description', 'user_profile__user__username']
    list_editable = ['status', 'priority']
    ordering = ['-priority', '-created_at']
